//
// Created by Max on 2025/5/28.
//

#ifndef ALL_MIC_DETECT_MIC_THREAD_H
#define ALL_MIC_DETECT_MIC_THREAD_H
#include "TvThread.h"
#include "MicConfig.h"
#include "SaveWav.h"
#include "hr_common.h"

class MicThread : public TvThread, public ITvThreadEvt{
public:
    MicThread();

    ~MicThread() override;

    int Init(int chanelNum,int sampleRate);

    int DeInit();

    bool isMicThreadRunning();

    static MicThread *getInstance();

private:
    void Run(const void *arg) override;
    void OnTvMWThreadExit(TvThread *pTvMWThread) override;
private:
    static MicThread *s_pMicThread;
    static std::mutex s_Mutex;
    MicConfig *m_pMtkConfig;
    SaveWav *m_pSaveWav;
    MI_U8 *m_pBuffer;

    MI_U32 mBufferSize;
    MI_U32 mFramesRead;
    MI_U32 mTotalFramesRead;
    MI_U32 mBytesPerFrame;
    bool m_bIsMicThreadRunning;
};



#endif //ALL_MIC_DETECT_MIC_THREAD_H
